public class ThreadDemo11Interrupted {
    public static void main(String[] args) throws InterruptedException {
        Thread t=new Thread(()->{
            while (!Thread.currentThread().isInterrupted()){
                System.out.println("hello world");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    //
//                    throw new RuntimeException(e);
                    break;
                    //加上break就是立刻终止
                    //不写东西就是不终止
                    //catch种先执行一些其他逻辑再break，就是稍后终止
                }
            }
            System.out.println("t结束");
        });
        t.start();
        Thread.sleep(3000);
        System.out.println("main线程尝试终止t线程");
        t.interrupt();
        System.out.println(t.isInterrupted());
    }
}
